import { useEffect, useState } from 'react'

type Xy = { x: number, y: number }
const useMouse = (): Xy => {
  const [x, setX] = useState<number>(0)
  const [y, setY] = useState<number>(0)
  useEffect(() => {
    function move(e: any) {
      setX(e.pageX)
      setY(e.pageY)
    }

    document.addEventListener('mousemove', move)
    return () => {
      document.removeEventListener('mousemove', move)
    }
  })
  return { x, y }
}
export default useMouse
